package org.jxht.web.api;

import org.jxht.dto.MajorDto;
import org.jxht.service.MajorServie;
import org.jxht.util.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by huang on 2017/3/24 0024.
 */
@Controller
@RequestMapping("JxhtWeb/MajorController")
public class MajorController {

    @Autowired
    private MajorServie majorServie;

    /**
     * 添加系
     * @param reuqestId 执行该功能的用户Id
     * @param requestJson Json字符串
     * @return String
     */
    @RequestMapping(value = "/{reuqestId}/addProfession")
    public String addProfession(@PathVariable(value = "reuqestId")int reuqestId,
                                @RequestParam(value = "requestJson")String requestJson){
        List<MajorDto> dtos = GsonUtil.parseJsonArrayWithGson(requestJson,MajorDto.class);
        for(MajorDto dto:dtos){
            majorServie.insertMajorService(dto);
        }
        return "SUCCESS";
    }

    /**
     * 删除系
     * @param majId 系编号
     * @return String
     */
    @RequestMapping(value = "/{majId}/deleteMajorInfo")
    public String deleteMajorInfo(@PathVariable(value = "majId")int majId){
        majorServie.deleteMajorService(new MajorDto(majId));
        return "SUCCESS";
    }

    /**
     * 获取单条系信息
     * @param requestId 系号
     * @return MajorDto
     */
    @RequestMapping(value = "/{requestId}/getMajorInfoSingle",method = RequestMethod.GET)
    @ResponseBody
    public MajorDto getMajorInfoSingle(@PathVariable(value = "requestId")int requestId){
        return majorServie.queryMajorServiceSingle(new MajorDto(requestId));
    }

    /**
     * 获取所有系的信息
     * @return
     */
    @RequestMapping(value = "/getMajorInfoAll",method = RequestMethod.GET)
    @ResponseBody
    public List<MajorDto> getMajorInfoAll(){
        return majorServie.queryMajorService(new MajorDto());
    }
}
